<?php

namespace App\Http\Middleware;

use Closure;
use Nette\Mail\Message;
use Nette\Mail\SmtpMailer;

class EmailMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $req = $next($request);

        //注册成功发送邮件
        if($request->user()) {
				//$website = config('settings.website');
                $mail = new Message;
                # 注意 , 下行的 setFrom 要和你的邮箱名保持一致
                $mail->setFrom('liyuhai <18825157239@163.com>')
                ->addTo($request->user()->email)
                ->setSubject('验证邮箱')
                // ->setBody(" 真好用 !");
                ->setHTMLBody('激活登录<a href="http://www.yancunju.com/auth/login">http://yancunju.com/auth/login</a> ');

                $mailer = new SmtpMailer(array(
                'host' => 'smtp.163.com',
                'username' => '18825157239',# 你的 163 用户名
                'password' => 'LYH1991'# 你的邮箱密码
                ));
                $mailer->send($mail);
        }

        return $req;
    }
}
